﻿using DemoApp3.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace DemoApp3.Controllers
{
    public class BaseController : Controller
    {
        protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            var authentication = HttpContext.GetOwinContext().Authentication;
            var ticket = authentication.AuthenticateAsync(AppConfig.AuthenticationType).Result;
            var identity = ticket != null ? ticket.Identity : null;

            if (identity != null)
            {
                ViewBag.IsAuthenticatedUser = identity.IsAuthenticated;
                ViewBag.AuthenticatedUserName = identity.Name;
            }

            ViewBag.ClientId = AppConfig.ClientId;

            ViewBag.AjaxCallAuthUrl = AppConfig.AuthorizationServerBaseAddress + AppConfig.AjaxCallAuthAddress;

            ViewBag.HeaderNameForAjaxAuth = AppConfig.HeaderNameForAjaxAuth;

            base.OnActionExecuting(filterContext);
        }
    }
}